﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLogical;
using Biz.Status;

namespace Biz.UserManagement
{
    public class Applicant : Employee, IApplicationActor
    {
        private Application application = null;

        public System.Data.DataTable ListAllTreatApplication()
        {
            return ApplicationTreat.ListAllWithApplicant(Id);
        }

        public System.Data.DataTable ListAllPresentApplication()
        {
            return ApplicationPresent.ListAllWithApplicant(Id);
        }

        public Application NewApplication(Application.ApplicationType _type)
        {
            application = (Application)Factory.Factory.getInstance().CreateProduct(_type.ToString());
            application.ApplicantID = Id;
            application.ApproverID = DefaultApproveID;
            application.CheckList = null;
            application.ExcuteDate = DateTime.Today;
            application.GaUser = null;
            application.Status = (ApplicationStatus)Factory.Factory.getInstance().CreateProduct(ApplicationStatus.StatusType.ToSubmit.ToString());
            return application;
        }

        public Applicant(int _id)
            : base(_id)
        {
        }

        public Applicant(int _id, Application _application)
            : base(_id)
        {
            application = _application;
        }

        public void SaveApplication()
        {
            application.save();
        }

        public void CancelApplication()
        {
            application.Status = (ApplicationStatus)Factory.Factory.getInstance().CreateProduct(ApplicationStatus.StatusType.Cancelled.ToString());
        }

        public void SubmitApplication()
        {
            if (application.Status.PRODUCT_NAME.Equals(ApplicationStatus.StatusType.ToSubmit.ToString()))
            {
                application.Status = (ApplicationStatus)Factory.Factory.getInstance().CreateProduct(ApplicationStatus.StatusType.ToApprove.ToString());
                SaveApplication();
            }
        }
    }
}
